import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import axios from "axios";
import store from "@/store";

const app = createApp(App)

app.use(store).use(ElementPlus).use(router).mount('#app')

console.log('环境:',process.env.NODE_ENV);
console.log('环境:',process.env.server);
axios.interceptors.request.use(function (config){
    console.log('请求参数：',config);
    const token = store.state.userinfo.token;
// if(Tool.isNotEmpty(token)){
    config.headers.token = token;
    console.log("请求headers增加token:",token);
// }
    return config;
},error =>{
    return Promise.reject(error);
});
axios.interceptors.response.use(function (response){
    console.log('返回结果：',response);
    return response;
},error =>{
    console.log('返回错误：',error);
    const response = error.response;
    const status = response.status;
    if(status === 401){
        console.log("未登录，跳到首页");
        router.push('/login');
        store.commit("setUserName",ncname.value);这里涉及到环境配置
        store.commit("setUserInfo", {});
        message.error("未登录或登录超时");


    }
    return Promise.reject(error);
});